﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Collections;

namespace NLite.Domain
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    [Contract]
    public interface IRepository<TEntity> : IRepository<TEntity, long> where TEntity : IEntity<long> { }
    /// <summary>
    /// 仓储接口，仓储是用来持久化实体对象
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <typeparam name="TIdentity"></typeparam>
    [Contract]
    public interface IRepository<TEntity,TIdentity> where TEntity : IEntity<TIdentity>
    {
        /// <summary>
        /// 
        /// </summary>
        IOrderedQueryable<TEntity> Query { get; }
        /// <summary>
        /// 根据标帜得到实体对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TEntity Get(TIdentity id);

        /// <summary>
        /// 返回所有的实体对象
        /// </summary>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TMember"></typeparam>
        /// <param name="pageIndex"></param>
        /// <param name="pageCount"></param>
        /// <param name="orderByExpression"></param>
        /// <param name="predicate"></param>
        /// <param name="ascending"></param>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll<TMember>(int pageIndex, int pageCount, Expression<Func<TEntity, TMember>> orderByExpression, Expression<Func<TEntity, bool>> predicate, bool ascending);

        /// <summary>
        /// 添加或更新实体对象到DB
        /// </summary>
        /// <param name="model"></param>
        void SaveOrUpdate(TEntity model);
        

        /// <summary>
        /// 通过标帜删除实体对象
        /// </summary>
        /// <param name="id"></param>
        void Delete(TIdentity id);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        void PhysicsDelete(TIdentity id);
    }

   
}
